package com.example.qxfw.backgroundManagement.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.qxfw.common.entity.UserTable;
import org.apache.ibatis.annotations.*;

import java.util.List;

/************************************
 *
 * @author : HuangDeYin Jolly
 * @since : JDK 11
 * @Date : 2023/7/3  星期一   16:45
 * @description : 此类用来 用户管理1
 ***************************************/
@Mapper
@DS("service")
public interface UserManagementFirstMapper {

    @Select("select username,password,servicewebaddress,servicewechataddress,inputtime,performer " +
            "from user_table order by username desc " +
            "limit 19 ")
    List<UserTable> selectUserTableLimit19();

    @Select("select distinct username " +
            "from user_table " +
            "limit #{a}")
    List<String> selectUserTableLimitA(int a);

    @Select("<script> " +
            "select username,password,servicewebaddress,servicewechataddress,inputtime,performer " +
            "from user_table " +
            "where username not in " +
            "<foreach item='userName' collection='userNames' open='(' separator=',' close=')'> " +
            "#{userName}" +
            "</foreach>" +
            "</script>")
    List<UserTable> selectUserTable(@Param("userNames") List<String> userNames);

    @Select("select count(username) from user_table")
    Integer selectNumber();

    @Select("<script> select username, password, servicewebaddress, servicewechataddress, inputtime, performer " +
            "from user_table where 1=1 " +
            "<if test='startTime!=null and endTime!=null'> and inputtime between #{startTime} and #{endTime}</if>" +
            "<if test='startTime!=null and endTime==null'> and inputtime &gt; #{startTime}</if>" +
            "<if test='startTime==null and endTime!=null'> and inputtime &lt; #{startTime}</if>" +
            "<if test='userName!=null'> and username like concat('%',#{userName},'%') </if>" +
            "</script>")
    List<UserTable> queryUserTable(@Param("startTime") String startTime, @Param("endTime") String endTime, @Param("userName") String userName);

    @Select("select username from user_table where username = #{userName}")
    List<UserTable> selectUserName(String userName);

    @Select("select id from user_table order by id desc limit 1")
    Integer selectIdMax();

    @Insert("insert into user_table(id, username, password, servicewebaddress, servicewechataddress, inputtime, performer) " +
            "VALUES (#{id}, #{userTable.username}, #{userTable.password}, #{userTable.servicewebaddress}, #{userTable.servicewechataddress}, #{userTable.inputtime}, #{userTable.performer})")
    Integer insertUserTable(@Param("id") int id, @Param("userTable") UserTable userTable);

    @Update("update user_table " +
            "set password=#{password},servicewebaddress=#{serviceWebAddress},servicewechataddress=#{serviceWechatAddress},inputtime=#{inputTime},performer=#{performer} " +
            "where username=#{userName}")
    Integer updateUserTable(@Param("userName") String userName, @Param("password") String password, @Param("serviceWebAddress") String serviceWebAddress, @Param("serviceWechatAddress") String serviceWechatAddress, @Param("inputTime") String inputTime, @Param("performer") String performer);

    @Delete("delete from user_table where username =#{userName}")
    Integer deleteUserTable(String userName);

    @Select("select id, username, password, servicewebaddress, servicewechataddress, inputtime, performer, permission, reservoirid, reservoirname, drainagearea, county, lon, lat, range " +
            "from user_table")
    List<UserTable> selectAllForExport();

    @Delete("truncate table user_table")
    Integer clearUserTable();

}
